﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// 信息类别逻辑类
    /// </summary>
    public class DocCls
    {
        /// <summary>
        /// 信息类类别数据类
        /// </summary>
        private readonly DAL.DocCls docClsDAL= new DAL.DocCls();
        /// <summary>
        /// 构造函数
        /// </summary>
		public DocCls()
		{}
        
        /// <summary>
        /// 获得数据列表,根据公司编号,根据排序字段排序 FIsUse=1
        /// <creator>wangl</creator>
        /// <date>2013-07-22</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns>信息类别列表</returns>
        public List<ElingOA6_Admin_DSJCJ.Model.DocCls> GetListByEntityNo(string entityNo)
        {
            return DataTableToList(docClsDAL.GetListByEntityNo(entityNo).Tables[0]);
        }
        /// <summary>
        /// 获得数据列表,根据公司编号,根据排序字段排序(全部数据)
        /// <creator>wangl</creator>
        /// <date>2013-08-09</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns>信息类别列表</returns>
        public List<ElingOA6_Admin_DSJCJ.Model.DocCls> GetListAllByEntityNo(string entityNo)
        {
            return DataTableToList(docClsDAL.GetListAllByEntityNo(entityNo).Tables[0]);
        }


        /// <summary>
        /// 获得数据列表,根据公司编号,根据排序字段排序(已启用的栏目)
        /// <creator>sunlj</creator>
        /// <date>2015-01-26</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns>信息类别列表</returns>
        public List<Model.DocCls> GetListIsUseByEntityNo(string entityNo)
        {
            return DataTableToList(docClsDAL.GetListIsUseByEntityNo(entityNo).Tables[0]);
        }

        /// <summary>
        /// 得到一个对象
        /// <creator>wangl</creator>
        /// <date>2013-07-23</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docClsCd">信息类别编号</param>
        /// <returns></returns>
        public Model.DocCls GetModel(string entityNo, string docClsCd)
        {
            return docClsDAL.GetModel(entityNo, docClsCd);
        }
        /// <summary>
        /// 获取下一级目录的个数
        /// <creator>wangl</creator>
        /// <date>2013-07-23</date>
        /// </summary>
        /// <param name="docClsCd">信息栏目编号</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>下级目录数量</returns>
        public int GetChildeCount(string docClsCd, string entityNo)
        {
            return docClsDAL.GetChildeCount(docClsCd, entityNo);
        }
        /// <summary>
        /// 修改数据的同时修改权限，权限先删除除部门，岗位，工作组之外的所有相关数据在增加新数据(事物模式)
        /// <creator>wangl</creator>
        /// <date>2013-07-31</date>
        /// </summary>
        /// <param name="docClsModel">信息类别实体类</param>
        /// <param name="docClsAuthorityList">权限列表</param>
        public void UpdateDocClsandDocClsAuthority(Model.DocCls docClsModel, List<Model.DocClsAuthority> docClsAuthorityList)
        {
            docClsDAL.UpdateDocClsandDocClsAuthority(docClsModel, docClsAuthorityList);
        }
        /// <summary>
        /// 更新栏目Logo相关的字段
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date> 
        /// </summary>
        /// <param name="imgUrl">图片url</param>
        /// <param name="imgOldName">图片名称</param>
        /// <param name="buffer">二进制</param>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docClsCd">栏目编号</param>
        public void EditDocClsLogoImg(string imgUrl, string imgOldName, byte[] buffer, string entityNo, string docClsCd)
        {
            docClsDAL.EditDocClsLogoImg(imgUrl, imgOldName, buffer, entityNo, docClsCd);
        }
        /// <summary>
        /// 修改页面顶部图片路径
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date> 
        /// </summary>
        /// <param name="imgUrl"></param>
        /// <param name="entityNo"></param>
        /// <param name="docClsCd"></param>
        public void EditTopPicPath(string imgUrl, string entityNo, string docClsCd)
        {
            docClsDAL.EditTopPicPath(imgUrl, entityNo, docClsCd);
        }
        /// <summary>
        /// 增加信息类别和信息类别权限(事物模式)
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date> 
        /// </summary>
        /// <param name="docClsModel">信息类别实体类</param>
        /// <param name="docClsAuthorityList">信息类别权限列表</param>
        public void AddDocClsAndDocClsAuthority(Model.DocCls docClsModel, List<Model.DocClsAuthority> docClsAuthorityList)
        {
            docClsDAL.AddDocClsAndDocClsAuthority(docClsModel, docClsAuthorityList);
        }
        /// <summary>
        /// 删除信息类别和信息类别权限(事务模式)
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date> 
        /// </summary>
        /// <param name="entityNo">公司编码</param>
        /// <param name="docClsCd">信息类别编码</param>
        /// <param name="isSingleDoc">是否是单信息</param>
        public void DeleteDocClsAndDocClsAuthority(string entityNo, string docClsCd, bool isSingleDoc)
        {
            docClsDAL.DeleteDocClsAndDocClsAuthority(entityNo, docClsCd, isSingleDoc);
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docClsCd">信息类别</param>
        /// <returns>true-存在 false-不存在</returns>
        public bool Exists(string entityNo, string docClsCd)
        {
            return docClsDAL.Exists(entityNo, docClsCd);
        }
        /// <summary>
        /// 获得数据列表,根据公司编号和上级编号
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date> 
        /// </summary>
        public List<Model.DocCls> GetListByEntityNoAndPreDocClsNo(string entityNo, string preDocClsNo)
        {
            return DataTableToList(docClsDAL.GetListByEntityNoAndPreDocClsNo(entityNo, preDocClsNo).Tables[0]);
        }
        /// <summary>
        /// 信息类别排序
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date> 
        /// </summary>
        /// <param name="docClsCds">信息类别编号集合</param>
        /// <param name="entityNo">公司编号</param>
        public void SeqDocClsTop(string[] docClsCds, string entityNo)
        {
            docClsDAL.SeqDocClsTop(docClsCds, entityNo);
        }
        /// <summary>
        /// 根据用户权限获取树目录
        /// <creator>wangl</creator>
        /// <date>2013-08-05</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="empNo">员工编号</param>
        /// <param name="deptNo">部门编号</param>
        /// <param name="authority">权限</param>
        /// <returns></returns>
        public DataTable GetListByAuthority(string entityNo, string empNo, string deptNo, string authority)
        {
            return docClsDAL.GetListByAuthority(entityNo, empNo, deptNo, authority).Tables[0];
            
        }
        /// <summary>
        /// 获得数据列表,可以推送到JCMS
        /// <creator>wangl</creator>
        /// <date>2013-11-20</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns>信息类别列表</returns>
        public DataTable GetListIsJcmsByEntityNo(string entityNo)
        {
            return docClsDAL.GetListIsJcmsByEntityNo(entityNo).Tables[0];

        }
        /// <summary>
        /// 特定栏目是否有特定的权限
        /// <creator>wangl</creator>
        /// <date>2013-08-06</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="empNo">员工编号</param>
        /// <param name="deptNo">部门编号</param>
        /// <param name="authority">权限</param>
        /// <param name="docClsNo">信息类别编号</param>
        /// <returns></returns>
        public bool ExistsAuthorityDocClsNo(string entityNo, string empNo, string deptNo, string authority, string docClsNo)
        {
            return docClsDAL.ExistsAuthorityDocClsNo(entityNo, empNo, deptNo, authority, docClsNo);
        }
        /// <summary>
        /// 根据编号，获取其父类编号和其组成的路径 01/02/03
        /// <creator>wangl</creator>
        /// <date>2013-08-13</date> 
        /// </summary>
        /// <param name="docClsCd">信息类别编号</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public string GetDocClsCdS(string docClsCd, string entityNo)
        {
            return docClsDAL.GetDocClsCdS(docClsCd, entityNo);
        }
        /// <summary>
        /// 获取信息类别名称路径名
        /// <creator>wangl</creator>
        /// <date>2013-08-14</date> 
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docClsCd">信息类别编号</param>
        /// <returns>名称路径名</returns>
        public string GetDocClsPathNames(string entityNo, string docClsCd)
        {
            return docClsDAL.GetDocClsPathNames(entityNo, docClsCd);
        }
        /// <summary>
        /// 获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-07-22</date> 
        /// </summary>
        /// <param name="dt">DataTable对象</param>
        /// <returns>信息类别列表</returns>
        private List<ElingOA6_Admin_DSJCJ.Model.DocCls> DataTableToList(DataTable dt)
        {
            List<ElingOA6_Admin_DSJCJ.Model.DocCls> modelList = new List<ElingOA6_Admin_DSJCJ.Model.DocCls>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ElingOA6_Admin_DSJCJ.Model.DocCls model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = docClsDAL.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }


        /// <summary>
        /// 获取信息类别数据，根据信息考核分中定义的需要考试的类别ID和相关年数 获取字段：FDocClsCd,fdocclsname,fpredocclscd
        /// <creator>sunlj</creator>
        /// <date>2013-10-16</date>
        /// </summary>
        /// <param name="strEntityNo">单位编号</param>
        /// <param name="strYear">年份</param>
        /// <returns></returns>
        public List<Model.DocCls> getDocClsByScore(string strEntityNo, decimal strYear)
        {
            DataSet ds = docClsDAL.getDocClsByScore(strEntityNo, strYear);
            return DataTableToListPart(ds.Tables[0]);
        }

        /// <summary>
        /// 获得某几个字段的数据列表 FDocClsCd,fdocclsname,fpredocclscd
        /// <creator>sunlj</creator>
        /// <date>2013-10-16</date>
        /// </summary>
        public List<Model.DocCls> DataTableToListPart(DataTable dt)
        {
            List<Model.DocCls> modelList = new List<Model.DocCls>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.DocCls model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.DocCls();
                    if (dt.Columns.Contains("FDocClsCd"))
                    {
                        model.FDocClsCd = dt.Rows[n]["FDocClsCd"].ToString();
                    }
                    if (dt.Columns.Contains("FPreDocClsCd"))
                    {
                        model.FPreDocClsCd = dt.Rows[n]["FPreDocClsCd"].ToString();
                    }
                    if (dt.Columns.Contains("FDocClsName"))
                    {
                        model.FDocClsName = dt.Rows[n]["FDocClsName"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获取专题专栏(已启用)
        /// <creator>wangl</creator>
        /// <date>2013-10-30</date>
        /// </summary>
        /// <param name="preDocClsID"></param>
        /// <param name="entityNo"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public Dictionary<string, string> GetIdAndLogUrl(string preDocClsID, string entityNo, int top = 0)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            DataSet ds = docClsDAL.GetIdAndLogUrl(preDocClsID, entityNo, top);
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                dic.Add(row["FDocClsCd"].ToString(), row["FLogoNewFileName"].ToString());
            }

            return dic;
        }


    }
}
